<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp" %>
<!DOCTYPE html>
<html lang="en">
<head>
    <!-- header -->
    <%@ include file="/WEB-INF/views/include/header.jsp" %>
    <link rel="stylesheet" href="<s:url value="/assets/css/main.css"></s:url>"/>
</head>
<style>
    body {
        background: #fff;
    }

    p {
        margin-top: 8px;
    }

    .information2 {
        border: 1px solid #ccc;
        padding-top: 8px;
        padding-bottom: 8px;
        margin-bottom: 10px;
    }

    .FeedbackContent1 {
        cursor: pointer !important;
    }

    .FeedbackContent2 {
        cursor: pointer !important;
    }

    .FeedbackContent3 {
        cursor: pointer !important;
    }
</style>
<body>

<%--上传成功模态框--%>
<div class="shade" style="display: none;"></div>
<div class="warning" style="display: none;">
    <p class="title"><em></em><span class="close">X</span></p>
    <p class="cont"></p>
    <div class="la-square-jelly-box la-3x">
        <div></div>
        <div></div>
    </div>
</div>

<form:form commandName="taskMain" cssClass="form-horizontal" role="form" onsubmit="return false"
           enctype="multipart/form-data" id="updateForm">
    <div class="col-sm-offset-1 row">
        <div class="form-group">
            <label class="control-label col-sm-1 no-padding-right">任务名称</label>
            <div class="col-sm-8">
                <input type="text" value="${taskMain.taskName}" class="form-control" readonly>
            </div>
        </div>
        <c:if test="${not empty taskMain.taskCont}">
            <div class="form-group">
                <label class="control-label col-sm-1 no-padding-right">任务内容</label>
                <div class="col-sm-8">
                    <input type="text" value="${taskMain.taskCont}" class="form-control" readonly>
                </div>
            </div>
        </c:if>
        <div class="form-group">
            <label class="control-label col-sm-1 no-padding-right">子事项</label>
            <div class="col-sm-8">
                <input type="text" value="${taskSub.subTaskName}" class="form-control" readonly>
            </div>
        </div>
            <%--<div class="form-group">--%>
            <%--<label class="control-label col-sm-1 no-padding-right">任务附件</label>--%>
            <%--<c:if test="${not empty taskMain.files}">--%>
            <%--<c:forEach items="${taskMain.files}" var="fileMap">--%>
            <%--${fileMap.file}--%>
            <%--</c:forEach>--%>
            <%--&lt;%&ndash;<div class="col-sm-8">&ndash;%&gt;--%>
            <%--&lt;%&ndash;<input type="text" readonly value="${taskMain.fileName}">&ndash;%&gt;--%>
            <%--&lt;%&ndash;<button class="btn btn-success" FileSysId ="${taskMain.file}" onclick="download(this)"><span&ndash;%&gt;--%>
            <%--&lt;%&ndash;class="glyphicon glyphicon-save"></span>下载附件&ndash;%&gt;--%>
            <%--&lt;%&ndash;</button>&ndash;%&gt;--%>
            <%--&lt;%&ndash;</div>&ndash;%&gt;--%>
            <%--</c:if>--%>
            <%--<c:if test="${empty taskMain.file}">--%>
            <%--<div class="col-sm-8">--%>
            <%--<input type="text" value="无任务附件" class="form-control" readonly>--%>
            <%--</div>--%>
            <%--</c:if>--%>
            <%--</div>--%>
            <%--循环附件下载--%>
        <div class="form-group">
            <label class="control-label col-sm-1 no-padding-right">附件:</label>
            <div class="col-sm-8">
                <c:if test="${not empty taskMain.files}">
                    <c:forEach items="${taskMain.files}" var="fileMap">
                        <div style="margin-bottom:15px;">
                            <input style="width: 70%;" type="text" class="fileName" readonly title="${fileMap.fileName}"
                                   value="${fileMap.fileName}" onclick="copyFile(this)">
                            <button class="btn btn-primary file" onclick="download(this)" FileSysId="${fileMap.file}">
                                下载附件
                            </button>
                        </div>
                    </c:forEach>
                </c:if>
                <c:if test="${empty taskMain.files}">
                    <input type="text" value="无附件" class=" col-sm-3 form-control" readonly>
                </c:if>
            </div>
        </div>
            <%-----以上为附件下载----%>
        <div class="form-group">
            <label class="control-label col-sm-1 no-padding-right">承办人</label>
            <div class="col-sm-8">
                <input type="text" value="${taskSub.userName}" class="form-control" readonly>
            </div>
        </div>


<%--        反馈列表--%>
        <c:if test="${!empty taskBackNewList}">
            <h3 class="col-sm-offset-5">反馈内容</h3>
            <c:forEach var="taskBackNew" items="${taskBackNewList}">
                <div class="col-sm-8 col-sm-offset-1 information2 row">
                        <%--  <div class="form-group">
                              <label class="control-label col-sm-offset-1 col-sm-1">反馈单位:</label>
                              <div class="col-sm-9">
                                  <input type="text" class="form-control" value="${taskBackNew.deptName}" readonly>
                              </div>
                          </div>--%>
                    <div class="form-group">
                        <label class="control-label col-sm-offset-1 col-sm-1">反馈人:</label>
                        <div class="col-sm-4">
                            <input type="text" class="form-control" value="${taskBackNew.senderName}" readonly>
                        </div>
                        <label class="control-label col-sm-1">反馈时间:</label>
                        <div class="col-sm-4">
                            <input type="text" class="form-control"
                                   value="${taskBackNew.createDate} ${taskBackNew.createTime}" readonly>
                        </div>
                    </div>
                    <div class="form-group">

                        <label class="control-label col-sm-offset-1 col-sm-1">反馈状态:</label>
                        <div class="col-sm-4">
                            <input type="text" class="form-control"
                                   value="${taskBackNew.status == 0 ? "未处理" :taskBackNew.status == 1 ? "办结" : taskBackNew.status == 2 ? "退回重办" : taskBackNew.status == 3 ? "已反馈" : "未知"}"
                                   readonly>
                        </div>
                    </div>
                        <%--循环附件下载--%>
                    <div class="form-group">
                        <label class="control-label col-sm-offset-1 col-sm-1">附件:</label>
                        <div class="col-sm-9">
                            <c:if test="${not empty taskBackNew.files}">
                                <c:forEach items="${taskBackNew.files}" var="fileMap">
                                    <div style="margin-bottom:15px;">
                                        <input style="width: 70%;" type="text" class="fileName" readonly
                                               title="${fileMap.fileName}"
                                               value="${fileMap.fileName}" onclick="copyFile(this)">
                                        <button class="btn btn-primary file" onclick="download(this)"
                                                FileSysId="${fileMap.file}">
                                            下载附件
                                        </button>
                                    </div>
                                </c:forEach>
                            </c:if>
                            <c:if test="${empty taskBackNew.files}">
                                <input type="text" value="无附件" class=" col-sm-3 form-control" readonly>
                            </c:if>
                        </div>
                    </div>
                        <%-----以上为附件下载----%>
                    <div class="form-group">
                        <label class="control-label col-sm-offset-1 col-sm-1">办理情况:</label>
                        <div class="col-sm-9">
                                <textarea rows="3" onclick="FeedbackContent(this)" FeedbackContent = "#FeedbackContent1" readonly class="form-control"
                                          type="text" style="resize: vertical;min-height: 50px">${taskBackNew.content}</textarea>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="control-label col-sm-offset-1 col-sm-1">存在问题:</label>
                        <div class="col-sm-9">
                            <textarea rows="3" onclick="FeedbackContent(this)" FeedbackContent = "#FeedbackContent2" readonly class="form-control"
                                      type="text" style="resize: vertical;min-height: 50px">${taskBackNew.problem}</textarea>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="control-label col-sm-offset-1 col-sm-1">下一步计划:</label>
                        <div class="col-sm-9">
                            <textarea rows="3" readonly onclick="FeedbackContent(this)" FeedbackContent = "#FeedbackContent3"  class="form-control"
                                      type="text" style="resize: vertical;min-height: 50px">${taskBackNew.plan}</textarea>
                        </div>
                    </div>

                </div>
                <hr/>
            </c:forEach>
        </c:if>


        <div class="form-group">
            <div class="col-sm-8 col-sm-offset-1 row" id="Feedback">
                <div class="information2 row">
                    <div>
                        <div class="form-group">
                            <div>
                                <label class="col-sm-1 col-sm-offset-1 control-label">办理情况</label>
                                <div class="col-sm-9">
                                    <textarea rows="3" class="form-control FeedbackContent" id="FeedbackContent1"
                                              placeholder="请输入办理情况"
                                              style="resize: vertical;min-height: 50px;"></textarea>
                                </div>
                            </div>
                        </div>
                        <div class="form-group">
                            <div>
                                <label class="col-sm-1 col-sm-offset-1 control-label">存在问题</label>
                                <div class="col-sm-9">
                                    <textarea rows="3" class="form-control FeedbackContent" id="FeedbackContent2"
                                              placeholder="请输入存在问题"
                                              style="resize: vertical;min-height: 50px;"></textarea>
                                </div>
                            </div>
                        </div>
                        <div class="form-group">
                            <div>
                                <label class="col-sm-1 col-sm-offset-1 control-label">下一步计划</label>
                                <div class="col-sm-9">
                                    <textarea rows="3" class="form-control FeedbackContent" id="FeedbackContent3"
                                              placeholder="请输入下一步计划"
                                              style="resize: vertical;min-height: 50px;"></textarea>
                                </div>
                            </div>
                        </div>
                        <div class="form-group">
                            <div>
                                <label class="col-sm-1 col-sm-offset-1 control-label">反馈附件</label>
                                    <%--<div class="col-sm-7 pos-rel">--%>
                                <div class="col-sm-9">
                                    <div id="uploader"></div>
                                        <%--<input type="file" class="form-control" id="fileupload">--%>
                                </div>
                                    <%--<div class="col-sm-2">--%>
                                    <%--<button class="btn btn-info" onclick="uploadFile(this,'file','fileName')">--%>
                                    <%--<span class="glyphicon glyphicon-open"></span>上传附件--%>
                                    <%--</button>--%>
                                    <%--</div>--%>
                            </div>
                        </div>
                        <c:if test="${taskUnit.unitType == '2'}">
                            <c:if test="${sysLogin.roleId == '02'}">
                                <input type="hidden" id="recipientId" value="${taskUnit.taskSubId}">
                            </c:if>
                            <c:if test="${sysLogin.roleId == '03' or sysLogin.roleId == '04' }">
                                <input type="hidden" id="recipientId" value="${userCreate}">
                            </c:if>
                        </c:if>
                        <c:if test="${taskUnit.unitType == '1'}">
                            <c:if test="${sysLogin.roleId == '02'}">
                                <input type="hidden" id="recipientId" value="${mainCreateUser}">
                            </c:if>
                        </c:if>
                        <c:if test="${sysLogin.roleId == '03' or sysLogin.roleId == '04' }">
                            <input type="hidden" id="recipientId" value="${userCreate}">
                        </c:if>
                    </div>
                    <div class="row">
                        <div class="col-sm-offset-3 col-sm-1">
                            <button class="btn btn-info btn-sm FeedbackConfirm" onclick="FeedbackConfirm()">确定</button>
                        </div>
                        <div class="col-sm-offset-4 col-sm-1">
                            <button class="btn btn-info btn-sm ">取消</button>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-1 text-right control-label">流程记录:</label>
            <div class="col-sm-9" style="margin-top: 30px">
                <c:forEach var="logNew" items="${logNewList}" varStatus="num">
                    <div class="row" style="margin-bottom: 5px">
                        <div class="col-sm-11"><span style="font-weight: bold;margin-right: 20px">${num.count}.</span>
                            <span style="font-weight: normal;margin-right: 20px"> ${logNew.createDate} ${logNew.createTime} </span>
                            <span style="font-weight: normal"> ${logNew.content}</span></div>
                            <%--<button class="btn-sm btn btn-info col-sm-1 urge" btnSysId = "${logNew.sysId}">催办</button>--%>
                    </div>
                </c:forEach>
            </div>
        </div>
        <input type="hidden" id="sysId" value="${taskSub.sysId}">
<%--
        <input type="hidden" id="taskSubId" value="${taskUnit.taskSubId}">
--%>
    </div>
</form:form>

<%--多选上传--%>
<script src="<s:url value="/assets/js/dist/easyUploader.jq.js"></s:url>"></script>

<script src="<s:url value="/assets/js/chosen.jquery.js"></s:url>"></script>
<script src="<s:url value="/assets/js/bootstrap.js"></s:url>"></script>
<script src="<s:url value="/assets/js/ajaxfileupload.js"></s:url>"></script>
<script src="<s:url value="/assets/js/modal/modal.js"></s:url>"></script>
<script src="<s:url value="/assets/js/date-time/bootstrap-datepicker.js"></s:url>"></script>
<script src="<s:url value="/assets/js/select2.js"></s:url>"></script>
<script src="<s:url value="/assets/js/jquery.gritter.js"></s:url>"></script>
<script src="<s:url value="/assets/js/own.js"></s:url>"></script>

<script>
    <%--多文件上传--%>
    var fileStr = "";//id字符串拼接
    var fileNameStr = "";//文件名字符串拼接
    var uploader = easyUploader({
        id: "uploader",
        accept: '.jpg,.png,.doc,.docx,.pdf,.xls,.xlsx,.ppt,.pptx',
        action: '/filesUpload/uploadFiles',
        dataFormat: 'formData',
        maxCount: 10,//允许上传的个数
        maxSize: 2000,//允许上传最大的容量
        multiple: true,
        data: null,
        beforeUpload: function (file, data, args) {
        },
        onChange: function (fileList) {
        },
        onRemove: function (removedFiles, files) {
            console.log('onRemove', removedFiles);
        },
        onSuccess: function (res) {
            console.log('onSuccess', res);
            if (res.data !== undefined && res.data[0] !== undefined) {
                //拼接文件id 和 文件名
                fileStr += res.data[0].sysid + ",";
                fileNameStr += res.data[0].oldName + ",";
            }
        },
        onError: function (err) {
            console.log('onError', err);
        },
    });
</script>

<script type="text/javascript">
    $(document).ready(function () {
        $("#e1").select2({
            placeholder: "请输入或点击选择经办人",
            width: "100%",
            closeOnSelect: false,
            allowClear: true,
        });
    });
    /**
     * 获取经办人
     */
    $("#Approval").click(function () {
        $("#Handle").show();
        $.get("/taskUnit/endorseList/" + $("#sysId").val() + "", function (data) {
            var option = "<option></option>"
            for (var i = 0; i < data.length; i++) {
                option += " <option value=" + data[i].sysId + ">" + data[i].name + "</option>"
            }
            $("#e1").html(option);
        })
    });

    function Handleremove() {
        $("#Handle").hide();
    }

    function addHandle(data) {
        $(data).siblings("input").val($(data).val().join(","));
    }

    /**
     *  ApprovalConfirm 批转确定
     */
    function ApprovalConfirm(e) {
        failure($(e), 1)
        var taskUsers = $("#e1").siblings("input").val();
        if (taskUsers == null || taskUsers == "") {
            return alert("请选择经办人");
        }
        var taskSubId = $("#taskSubId").val();
        var sysId = $("#sysId").val();


        var datas = {
            sysId: sysId,
            taskSubId: taskSubId,
            taskUsers: taskUsers,

        };
        $.post("/taskUnit/saveTaskUser", datas, function (data) {
            if (data.code == 200) {
                failure($(e), 0)
                alert(data.message);
                setTimeout(function () {
                    //刷新当前页面
                    open(location, '_self').close();
                }, 50)
            } else {
                alert(data.message);
            }
        })
    }

    /**
     *反馈人 FeedbackPerson
     */
    (function () {
        var sysId = $("#sysId").val();

    })();

    /**
     * 动态获取反馈内容
     */
    $(document).on("click", ".FeedbackContent1", function () {
        var html = $("#FeedbackContent1").val();
        var text = $(this).val();
        html += text;
        $("#FeedbackContent1").val(html);

    });
    $(document).on("click", ".FeedbackContent2", function () {
        var html = $("#FeedbackContent2").val();
        var text = $(this).val();
        html += text;
        $("#FeedbackContent2").val(html);

    });
    $(document).on("click", ".FeedbackContent3", function () {
        var html = $("#FeedbackContent3").val();
        var text = $(this).val();
        html += text;
        $("#FeedbackContent3").val(html);

    });

    /**
     *  确认反馈内容
     */

    function FeedbackConfirm() {
        failure(".FeedbackConfirm", 1)
        var FeedbackContent1 = $("#FeedbackContent1").val();
        var FeedbackContent2 = $("#FeedbackContent2").val();
        var FeedbackContent3 = $("#FeedbackContent3").val();
        var sysId = $("#sysId").val();
        var FeedbackName = $("#recipientId").val();
        if (!FeedbackContent1) {
            failure(".FeedbackConfirm", 0)
            return alert("请输入办理情况")
        }

        var datas = {
            situations: FeedbackContent1,
            problems: FeedbackContent2, //存在问题
            nextPlan: FeedbackContent3,  //下一步计划
            //recipientId: FeedbackName,
            sysId: sysId,
            fileIds: fileStr,
            fileName: fileNameStr
        }
        $.post("/insideDept/backTasks", datas, function (data) {
            console.log(data);
            if (data.code == 200) {
                alert(data.message);
                setTimeout(function () {
                    //刷新当前页面
                    open(location, '_self').close();
                }, 50)
            } else {
                alert(data.message);
            }
            failure(",FeedbackConfirm", 0)
        })

    }

    /**
     *  我的反馈状态
     */
   /* $(".updateStatus").click(function () {
        var $this = $(this);
        var status = 2;
        var taskBackId = $this.attr("updateStatus");
        $.post("/taskUnit/updateStatus", {taskBackId: taskBackId, status: status}, function (data) {
            if (data.code == 200) {
                alert(data.message);
                setTimeout(function () {
                    //刷新当前页面
                    open(location, '_self').close();
                }, 50)
            } else {
                alert(data.message);
            }
        })
    });*/





  /*  $(".clickFeedback").click(function () {
        var $parent = $(this).parent().parent().parent();
        var FeedbackContent1 = $parent.find(".FeedbackContent1").val();
        var FeedbackContent2 = $parent.find(".FeedbackContent2").val();
        var FeedbackContent3 = $parent.find(".FeedbackContent3").val();
        var file = $parent.find(".file").attr("FileSysId");
        var filename = $parent.find(".fileName").val();
        var FeedbackName = $("#recipientId").val();
        var sysId = $("#sysId").val();

        var datas = {
            situations: FeedbackContent1,
            problems: FeedbackContent2, //存在问题
            nextPlan: FeedbackContent3,  //下一步计划
           // recipientId: FeedbackName,
            sysId: sysId,//子任务id
            file: file,
            fileName: filename
        }
        $.post("/taskUnit/taskBackNew", datas, function (data) {
            console.log(datas);
            if (data.code == 200) {
                alert(data.message);
                setTimeout(function () {
                    //刷新当前页面
                    open(location, '_self').close();
                }, 50)
            } else {
                alert(data.message);
            }
        })
    });*/
    // 关闭
    // parent.close_current_app();
</script>
</body>
</html>